<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>NGIS Charity Bike Ride</title>
    <script src="http://www.google.com/jsapi?key=ABQIAAAAuPsJpk3MBtDpJ4G8cqBnjRRaGTYH6UMl8mADNa0YKuWNNa8VNxQCzVBXTx2DYyXGsTOxpWhvIG7Djw" type="text/javascript"></script>
	<link rel=stylesheet href="{{=URL('static','css/custom.css')}}" />
	<link rel="shortcut icon" href="{{=URL('static','images/favicon.ico')}}" />
    {{include 'web2py_ajax.html'}}
    
    <!-- We'll need to walk the DOM looking for features of a certain type later -->
    <script src="http://earth-api-samples.googlecode.com/svn/trunk/lib/kmldomwalk.js" type="text/javascript"></script>

    <script type="text/javascript">
    var ge;
    
    var tour = null;
    
    google.load("earth", "1");
    
    function init() {
      google.earth.createInstance('map3d', initCallback, failureCallback);

    }
    
    function initCallback(instance) {
	
      ge = instance;
      ge.getWindow().setVisibility(true);
	  
	  google.earth.addSideDatabase(
        ge, 'https://mapsengine.google.com/09372590152434720789-08196709414522434935-4/kh/',
          sideDatabaseSuccess,
          sideDatabaseFail,
          {
            userName: '',
            password: ''
          }
      );
    
      // add a navigation control
      ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO);
    
      // add some layers
	  ge.getLayerRoot().enableLayerById(ge.LAYER_BUILDINGS, true);
    
      // create the tour by fetching it out of a KML file
      var href = 'https://s3-ap-southeast-2.amazonaws.com/ngis/CharityRideTour.kml';
    
      google.earth.fetchKml(ge, href, function(kmlObject) {
		
        if (!kmlObject) {
          // wrap alerts in API callbacks and event handlers
          // in a setTimeout to prevent deadlock in some browsers
          setTimeout(function() {
            alert('Bad or null KML.');
          }, 0);
          return;
        }
		
        // Show the entire KML file in the plugin.
        ge.getFeatures().appendChild(kmlObject);
		
        // Walk the DOM looking for a KmlTour
        walkKmlDom(kmlObject, function() {
          if (this.getType() == 'KmlTour') {
            tour = this;
			ge.getTourPlayer().setTour(tour);
            return false; // stop the DOM walk here.
          }
        });
      });

    }
    
    function failureCallback(errorCode) {
    }
	
	function sideDatabaseSuccess(db) {
	  side_database = db; // Note that side_database is not declared anywhere.
	  // the above is a hack to work around a bug with the google earth plugin.
	  // Google are investigating this issue: https://code.google.com/p/maps-engine/issues/detail?id=21
    }

    function sideDatabaseFail() {
    }
    
    </script>
  </head>
  <body onload="init()" style="font-family: arial, sans-serif; font-size: 13px; border: 0;">
	<div class="wrapper">
		<div id="header">
			<p><a href="http://www.ngis.com.au" target = "_blank"><img src="http://www.ngis.com.au/ngisweb/wp-content/themes/NGIS/images/ngis_logo.png"></a><div id="title">Charity Bike Ride 2013</div></p>
		</div>
		<div id="map3d" style="width: 950px; height: 550px; margin:0 auto;"></div>
		<br><p><span style = "color: #005581; font-style: bold;">For more information please visit:</span><a href="http://www.ngis.com.au" target = "_blank">www.ngis.com.au</a></p>
		<div class="push"></div>
	</div>
	<div id="footer"></div>
  </body>
</html>